package com.zhang.zhangapp.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.makeramen.roundedimageview.RoundedImageView;
import com.zhang.zhangapp.R;
import com.zhang.zhangapp.bean.user.Message;

import org.xutils.common.util.DensityUtil;
import org.xutils.image.ImageOptions;
import org.xutils.view.annotation.ViewInject;
import org.xutils.x;

import java.util.List;
import java.util.Random;

/**
 * Created by Administrator on 2018/4/16.
 */

public class MessageAdapter extends BaseAdapter {

    private List<Message> messageList;
    private Context context;
    private Random random = new Random();

    private int[] test = new int[]{R.mipmap.phone_mesage,R.mipmap.buy_coupon,R.mipmap.activity_message,R.mipmap.consumption,R.mipmap.recharge};
    ImageOptions imageOptions = new ImageOptions.Builder()
            .setImageScaleType(ImageView.ScaleType.CENTER_CROP)
            .setRadius(100)
            .setIgnoreGif(false)
            .setCrop(true)//是否对图片进行裁剪
            .setFailureDrawableId(R.mipmap.test)
            .setLoadingDrawableId(R.mipmap.test)
            .build();
    public MessageAdapter(List<Message> messageList, Context context) {
        this.messageList = messageList;
        this.context = context;
    }

    @Override
    public int getCount() {
        return messageList == null ? 10 : messageList.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder vh = null;
        if (view == null) {
            vh = new ViewHolder();
            view = LayoutInflater.from(context).inflate(R.layout.item_message,null);
            x.view().inject(vh,view);
            vh.imageView = (RoundedImageView)view.findViewById(R.id.message_image);
            view.setTag(vh);
        }else{
            vh = (ViewHolder)view.getTag();
        }
        int index = random.nextInt(5);

//        Message message = messageList.get(i);
        vh.imageView.setImageResource(test[index]);
//        vh.cTimeText.setText(message.getCtime());
//        vh.descText1.setText(message.getInfodesc());
//        vh.descText.setText("");
//        vh.nameText.setText(message.getTitle());
        return view;
    }

    class ViewHolder {
        RoundedImageView imageView;
        @ViewInject(R.id.message_name)
        TextView nameText;
        @ViewInject(R.id.message_time)
        TextView cTimeText;
        @ViewInject(R.id.message_des)
        TextView descText;
        @ViewInject(R.id.message_des1)
        TextView descText1;
    }
}
